# -*- coding: utf-8 -*-
# @File  : 连接oracle数据库.py
# @Author: zbh
# @Date  : 2025/6/6_10:08


import cx_Oracle
import os
import pandas as pd
# 连接到 Oracle 数据库

os.environ["NLS_LANG"] = "SIMPLIFIED CHINESE_CHINA.AL32UTF8"  # 常见 UTF-8 配置

def getdata():
    '''
    账号密码是：ACPBOOT
    ip地址是：192.168.99.105
    端口号是：15210
    数据库服务名是：ORCL
    :return:
    '''
    # 连接到 Oracle 数据库
    # connection = cx_Oracle.connect('ACPBOOT', 'ACPBOOT', '192.168.99.105:15210/ORCL')
    connection = cx_Oracle.connect(
        user='ACPBOOT',
        password='ACPBOOT',
        dsn='192.168.99.105:15210/ORCL',
        encoding='UTF-8',
        timezone='+00:00'  # 与数据库时区一致
    )
    # 创建游标
    cursor = connection.cursor()
    # 执行查询
    cursor.execute("SELECT * FROM T_PA_PRODUCT tpp WHERE FNAME LIKE '%zbh%'")
    # 获取查询结果
    rows = cursor.fetchall()
    # 打印查询结果
    for row in rows:
        print(row)
    # 关闭游标和连接
    cursor.close()
    connection.close()


getdata()







